<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<form method="post" action="{$ADMIN_SCRIPT}/cms/category/{$dispatches[method]}&id={$_var[gp_id]}&parentid={$_var[gp_parentid]}" onsubmit="javascript:return check_form(this);">
				<input type="hidden" name="formsubmit" value="yes" />
				<input type="hidden" name="hdnFile01" value=""/>
				<input type="hidden" name="hdnFile02" value=""/>
				<div class="well widget">
					<div class="widget-header">
						<p class="text">* {lang admin.validate.require}</p>
					</div>
					<div class="widget-content">
						<fieldset>
							<label>{lang cms.category_edit.view.parent.label}</label>
							<span class="text-info">
								<!--{if $parent !== null}-->
								{$parent[CNAME]}({$parent[IDENTITY]})
								<!--{else}-->
								{lang cms.category_edit.view.parent.tips}
								<!--{/if}-->
							</span>
							
							<hr/>
							<label>{lang cms.category_edit.view.dispalyorder.label} *</label>
							<input type="text" class="input-mini" name="txtDisplayOrder" placeholder="{lang cms.category_edit.view.dispalyorder.placeholder}..." maxlength="3" value="{$category[DISPLAYORDER]}" /> 
							<span class="help-inline">{lang cms.category_edit.view.dispalyorder.tips}</span>
							
							<label>{lang cms.category_edit.view.cname.label} *</label>
							<input type="text" class="input-large" name="txtCName" placeholder="{lang cms.category_edit.view.cname.placeholder}..." maxlength="50" value="{$category[CNAME]}" /> 
							<span class="help-inline">{lang cms.category_edit.view.cname.tips}</span>
							
							<label>{lang cms.category_edit.view.identity.label} *</label>
							<input type="text" class="input-large" name="txtIdentity" placeholder="{lang cms.category_edit.view.identity.placeholder}..." maxlength="30" value="{$category[IDENTITY]}" /> 
							<span class="help-inline">{lang cms.category_edit.view.identity.tips}</span>
							
							<label>{lang cms.category_edit.view.comment.label}</label>
							<textarea class="span6" rows="4" name="txtComment" placeholder="{lang cms.category_edit.view.comment.placeholder}...">{$category[COMMENT]}</textarea>
							<span class="help-inline">{lang cms.category_edit.view.comment.tips}</span>
							
							<hr/>
							<label>{lang cms.category_edit.view.file.label}</label>
							<table class="swfupload">
								<tr>
									<td width="240" valign="top" align="center">
										<p class="img" id="p_file01">
											<!--{if is_array($category['FILE01'])}-->
											<img src="{$category[FILE01][0]}" data="{$category[FILE01][4]}" width="240" style="width:240px;" border="0"/>
											<!--{else}-->
											<img src="static/images/no-picture.jpg" data="" width="240" style="width:240px;" />
											<!--{/if}-->
										</p>
										<hr/>
										<div class="upload-button"><span id="swfu_file01"></span></div>
									</td>
									<td width="50"></td>
									<td width="10" style="border-left:1px solid #ccc;"></td>
									<td width="30"></td>
									<td width="160" valign="top" align="center">
										<p class="img" id="p_file02">
											<!--{if is_array($category['FILE02'])}-->
											<img src="{$category[FILE02][0]}" data="{$category[FILE02][4]}" width="160" style="width:160px;" border="0"/>
											<!--{else}-->
											<img src="static/images/no-picture.jpg" data="" width="160" style="width:160px;" />
											<!--{/if}-->
										</p>
										<hr/>
										<div class="upload-button"><span id="swfu_file02"></span></div>
									</td>
								</tr>
							</table>
							
							<hr/>
							<label>{lang cms.category_edit.view.url.label}</label>
							<input type="text" class="input-xlarge" name="txtUrl" placeholder="{lang cms.category_edit.view.url.placeholder}" maxlength="150" value="{$category[URL]}" /><br/>
							<span class="help-inline">{lang cms.category_edit.view.url.tips}</span>
							<p class="thin">&nbsp;</p>
							<label>{lang cms.category_edit.view.isaudit.label}</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsAudit" class="fancy" value="1"  {if $category['ISAUDIT'] == 1}checked="checked"{/if}/> {lang cms.category_edit.view.isaudit.yes.label} 
							</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsAudit" class="fancy" value="0" {if $category['ISAUDIT'] == 0}checked="checked"{/if}/> {lang cms.category_edit.view.isaudit.no.label}
							</label>
							
							<hr/>
							<label>
								<input type="checkbox" class="fancy" name="cbxSetupColumn" value="1" {if count($category['FILES']) > 0 || count($category['COLUMNS']) > 0}checked="checked"{/if}/>
								{lang cms.category_edit.view.colum.label}
							</label>
							<table class="table" style="width:auto; display:{echo count($category['FILES']) > 0 || count($category['COLUMNS']) > 0 ? '' : 'none';};" id="tbl_column">
								<thead>
									<th width="90">{lang cms.category_edit.view.colum.th.name}</th>
									<th width="350">{lang cms.category_edit.view.colum.th.setup}</th>
									<th width="60">{lang cms.category_edit.view.colum.th.hidden}</th>
								</thead>
								<tr class="tr-address">
									<td>{lang cms.category_edit.view.colum.td.address}</td>
									<td><input type="text" name="txtColumn[ADDRESS]" class="input" value="{$category[COLUMNS][ADDRESS][text]}" maxlength="10"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[ADDRESS]" value="1" {if $category['COLUMNS']['ADDRESS']['show']}checked="checked"{/if}/></td>
								</tr>
								<tr class="tr-author">
									<td>{lang cms.category_edit.view.colum.td.author}</td>
									<td><input type="text" name="txtColumn[AUTHOR]" class="input" value="{$category[COLUMNS][AUTHOR][text]}" maxlength="10"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[AUTHOR]" value="1" {if $category['COLUMNS']['AUTHOR']['show']}checked="checked"{/if}/></td>
								</tr>
								<tr class="tr-keywords">
									<td>{lang cms.category_edit.view.colum.td.keywords}</td>
									<td><input type="text" name="txtColumn[KEYWORDS]" class="input" value="{$category[COLUMNS][KEYWORDS][text]}" maxlength="10"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[KEYWORDS]" value="1" {if $category['COLUMNS']['KEYWORDS']['show']}checked="checked"{/if}/></td>
								</tr>
								<tr class="tr-link">
									<td>{lang cms.category_edit.view.colum.td.link}</td>
									<td><input type="text" name="txtColumn[LINK]" class="input" value="{$category[COLUMNS][LINK][text]}" maxlength="10"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[LINK]" value="1" {if $category['COLUMNS']['LINK']['show']}checked="checked"{/if}/></td>
								</tr>
								<tr class="tr-summary">
									<td>{lang cms.category_edit.view.colum.td.summary}</td>
									<td><input type="text" name="txtColumn[SUMMARY]" class="input" value="{$category[COLUMNS][SUMMARY][text]}" maxlength="10"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[SUMMARY]" value="1" {if $category['COLUMNS']['SUMMARY']['show']}checked="checked"{/if}/></td>
								</tr>
								<tr>
									<td>{lang cms.category_edit.view.colum.td.content}</td>
									<td><input type="text" name="txtColumn[CONTENT]" class="input" value="{$category[COLUMNS][CONTENT][text]}" maxlength="10"/></td>
									<td>
										<select name="sltColumn[CONTENT]">
									        <option value="0" {if $category['COLUMNS']['CONTENT']['type'] == 0}selected="selected"{/if}>{lang cms.category_edit.view.colum.td.content.type.0}</option>
									        <option value="1" {if $category['COLUMNS']['CONTENT']['type'] == 1}selected="selected"{/if}>{lang cms.category_edit.view.colum.td.content.type.1}</option>
									        <option value="2" {if $category['COLUMNS']['CONTENT']['type'] == 2}selected="selected"{/if}>{lang cms.category_edit.view.colum.td.content.type.2}</option>
								        </select>
									</td>
								</tr>
								<tr>
									<td>{lang cms.category_edit.view.colum.td.file.tips}</td>
									<td><input type="text" name="txtFiles" class="input span11" value="{$category[FILES][text]}" maxlength="100"/></td>
									<td><input type="checkbox" class="fancy" name="cbxColumn[FILES]" value="1" {if $category['FILES']['show']}checked="checked"{/if}/></td>
								</tr>
							</table>
							
							<hr/>
							<!--{if $dispatches['method'] == '_add'}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][add]}>{lang admin.operation.submit}</button>
							<!--{elseif $dispatches['method'] == '_update'}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</button>
							<!--{/if}-->
							<button type="reset" class="btn btn-small">{lang admin.operation.reset}</button>
							<button type="button" class="btn btn-small" onclick="javascript:location.href='{$ADMIN_SCRIPT}/cms/category&parentid={$_var[gp_parentid]}';">{lang admin.operation.go.back}</button>
						</fieldset>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<script type="text/javascript" src="static/plugins/swfupload.js"></script>
<script type="text/javascript" src="static/plugins/swfupload_handlers.js"></script>
<script type="text/javascript" src="static/plugins/swfupload_images.js"></script>

<script>
var swfu_file01 = null;
var swfu_file02 = null;

swfupload_params.limit = 1;
swfupload_params.uploaded = 0;

function fileQueueError(file, errorCode, message) {
	if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
		$.dialog({message:'{lang admin.validate.swfupload.lang.limit}'});
	}else{
		$.dialog({message:'{lang admin.validate.swfupload.echo.fail}'});
	}
}

function uploadSuccess(file, serverData) {
	if(serverData.substring(0, 7) === "FILEID:") {
		var tempArr = serverData.split('|');
		var photoPath = formatFilePath(serverData.substring(7));
		
		$('#p_' + tempArr[5] + ' img').attr('src', photoPath).attr('data', serverData.substring(7));
	}else $.dialog({message:serverData});
}

function createSwfUpload(file, title){
	var swf_config = {
		upload_url: "{$ADMIN_SCRIPT}/cms/category/_upload&file=" + file + "&_SALT={$_var[current][SALT]}",
		
		file_size_limit : "200KB", 
		file_types : "*.jpg;*.bmp;*.gif;*.png",
		file_types_description : "JPG Images",
		file_upload_limit : "0",
		
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		button_image_url : "static/images/swfupload/swfupload.png",
		button_placeholder_id : "swfu_" + file,
		button_width: 120,
		button_height: 18,
		button_text : '{lang admin.validate.swfupload.lang.button.choice}' + title + '({lang admin.validate.swfupload.lang.button.size.200})',
		button_text_style : '',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		
		flash_url : "static/swfupload.swf", 
		debug: false
	};
	
	return new SWFUpload(swf_config);
}

function check_form(frm){
    if(frm.txtDisplayOrder.value.trim().length == 0){
    	$(frm.txtDisplayOrder).next('.help-inline').css('color', 'red');
    	frm.txtDisplayOrder.focus();
    	return false;
    }
    
    if(!frm.txtDisplayOrder.value.trim().isInt()){
    	$(frm.txtDisplayOrder).next('.help-inline').css('color', 'red');
    	frm.txtDisplayOrder.focus();
    	return false;
    }
    
    if(frm.txtCName.value.trim().length == 0){
    	$(frm.txtCName).next('.help-inline').css('color', 'red');
    	frm.txtCName.focus();
    	return false;
    }
    
    if(frm.txtIdentity.value.trim().length == 0){
    	$(frm.txtIdentity).next('.help-inline').css('color', 'red');
    	frm.txtIdentity.focus();
    	return false;
    }
    
    frm.hdnFile01.value = $('#p_file01 img').attr('data') ? $('#p_file01 img').attr('data') : '';
    frm.hdnFile02.value = $('#p_file02 img').attr('data') ? $('#p_file02 img').attr('data') : '';
    
    return true;
}

$(function(){
	$('.fancy').uniform();
	
	$('fieldset input,textarea').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$("input[name='cbxSetupColumn']").click(function(){
		if(this.checked) $('#tbl_column').show();
		else $('#tbl_column').hide();
	});
	
	$('#tbl_column .btn').click(function(){
		var self = this;
		
		$.dialog({submit:'{lang admin.operation.submit}', href:'{$ADMIN_SCRIPT}/cms/category&op=module&id=' + $(self).attr('ref'), callback: function(){
			$('#modal_dialog .btn-primary').click(function(){
				alert(1);
			});
		}});
	});
	
	$('.swfupload img').dblclick(function(){
		$(this).attr({src:'static/images/no-picture.jpg', data:''});
	});
	
	swfu_file01 = createSwfUpload('file01', '{lang cms.category_edit.view.file.01}');
	swfu_file02 = createSwfUpload('file02', '{lang cms.category_edit.view.file.02}');
});
</script>
<!--{template /module/admin/view/foot}-->